package a_java_48_day.day7;
/**
 * 括号匹配
 */

import java.util.*;

public class Parenthesis {
    public boolean chkParenthesis(String A, int n) {
        // write code here
        Stack <Character> stack= new Stack<>();
        for(int i=0;i<A.length();i++){
            if(A.charAt(i)!='('&&A.charAt(i)!=')'){
                return false;
            }
        }
        for(int j=0;j<A.length();j++){
            if(A.charAt(j)=='('){
                stack.push(A.charAt(j));
                continue;
            }
            if(A.charAt(j)==')'){
                if(stack.peek()==null){
                    return false;
                }else{
                    stack.pop();
                }
                continue;
            }
        }
        return true;
    }
}